
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>对话</title>
    <link rel="stylesheet" type="text/css" href="../../../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../../../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../../../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../../css/aui-pull-refresh.css" />
    <link rel="stylesheet" type="text/css" href="../../../../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../../../../css/style.css" />
    <style>
        html,
        body {
            background: #f4f4f4;
            position: relative;
            font-size: 20px!important;
        }

        .content {
            width: 100%;
            float: left;
            box-sizing: border-box;
            padding: 0 0.2rem;
        }

        .massage {
            width: 80%;
            min-height: 3.95rem;
            /*background: red;*/
            margin: 1.25rem 0;
            float: left;
            position: relative;
        }

        .head_img {
            width: 3.95rem;
            height: 3.9rem;
            border-radius: 0.4rem;
            position: absolute;
        }

        .text_content {
            width: 100%;
            height: 100%;
            background: #fff;
            background-color: #ffffff;
            box-shadow: 0rem 0rem 1.2rem 0rem rgba(126, 126, 126, 0.16);
            border-radius: 0.4rem;
            padding: 0.9rem 0 0.9rem 0;
            box-sizing: border-box;
            font-size: 1.5rem;
            line-height: 2.2rem;
        }

        .head_img_src {
            width: 100%;
            height: 100%;
            border-radius: 0.4rem;
        }

        .self {
            float: right;
            right: 0;
        }

        .aui-chat .aui-chat-media img {
            height: 1.95rem;
            border-radius: 0.4rem;
        }

        .aui-chat .aui-chat-right .aui-chat-inner {
            width: 100%;
        }

        .bottom {
            width: 100%;
            float: left;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="content">
            <section class="aui-chat">
                <template v-for='(item,key) in content'>
                    <template v-if='item.talk_type=="talk"'>
                        <div class="aui-chat-item " :class="item.type==0?'aui-chat-right':'aui-chat-left'">
                            <div class="aui-chat-media">
                                <img :src="item.head_img" />
                            </div>
                            <div class="aui-chat-inner">
                                <!-- <div class="aui-chat-name">{{item.name}}</div> -->
                                <div class="aui-chat-content">
                                    <div class="aui-chat-arrow"></div>
                                    <template v-if='item.is_img==0'>
                                        <!-- {{item.content}} -->
                                        <span v-html='item.content'></span>
                                    </template>
                <template v-else>
                                        <img :src="item.img" alt="">
                                    </template>
        </div>
    </div>
    </div>
    </template>
    <template v-else>
                    <div class="aui-chat-header">2016年7月13日</div>
                    </template>
    </template>
    </section>
    </div>
    <div class="bottom" id="bottom"></div>
    </div>
</body>
<script type="text/javascript" src="../../../../script/api.js"></script>
<script type="text/javascript" src="../../../../script/zepto.js"></script>
<script type="text/javascript" src="../../../../script/vue.min.js"></script>
<script type="text/javascript" src="../../../../script/swiper.min.js"></script>
<script type="text/javascript" src="../../../../script/utils.js"></script>
<script type="text/javascript" src="../../../../script/common.js"></script>
<script type="text/javascript" src="../../../../script/aui-tab.js"></script>
<script type="text/javascript" src="../../../../script/aui-scroll.js"></script>
<script type="text/javascript" src="../../../../script/aui-pull-refresh.js"></script>
<script type="text/javascript" src="../../../../script/axios.min.js"></script>
<script type="text/javascript" src="../../../../script/axios-config.js"></script>
<script type="text/javascript">
    apiready = function() {
        var UIChatTools = api.require('UIChatTools');
        var rong = api.require('rongCloud2');

        new Vue({
            el: "#app",
            data: {
                user_info: $api.getStorage("user_info"),
                content: [],
                oldid:""
            },
            mounted: function() {
                var that = this
                rong.init(function(ret, err) {
                    if (ret.status == 'success') {
                        //消息监听
                        jtxx(that);
                        rong.connect({
                            token: $api.getStorage('rong_token')
                        }, function(ret, err) {
                            console.log(JSON.stringify(ret))
                            console.log(JSON.stringify(err))
                        });
                    } else {
                        api.toast({
                            msg: '融云初始化失败',
                        });
                    }
                });
                function getLatestMessages(targetId, conversationType) {
                    var rong = api.require('rongCloud2');
                    rong.getLatestMessages({
                        conversationType: conversationType,
                        targetId: targetId,
                        count: 4
                    }, function(ret, err) {
                        var content = that.content
                        if (ret.status == 'success') {
                            if (ret.result && ret.result.length > 0) {
                                console.log(JSON.stringify(ret.result))
                                console.log(ret.result[ret.result.length - 1].messageId)
                                that.oldid= ret.result[ret.result.length - 1].messageId
                                for (var i = ret.result.length - 1; i >= 0; i--) {
                                    var rs = ret.result[i];
                                    if (rs.objectName == 'RC:TxtMsg') {
                                        jsxx = rs.content.text.replace(reg, function(a, b) {
                                            return face[a] ? face[a] : a;
                                        });
                                        if (rs.senderUserId==that.user_info.user_id) {
                                            var data = {
                                                talk_type: "talk",
                                                type: '0',
                                                name: that.user_info.username,
                                                head_img: that.user_info.head_img,
                                                content: jsxx,
                                                is_img: 0,
                                            }
                                        } else {
                                            var data = {
                                                talk_type: "talk",
                                                type: '1',
                                                name: api.pageParam.uname,
                                                head_img: api.pageParam.uimg,
                                                content: jsxx,
                                                is_img: 0,
                                            }
                                        }
                                        content.push(data)
                                        that.content = content
                                    } else if (rs.objectName == 'RC:ImgMsg') {
                                        var bpic = rs.content.imageUrl;
                                        var spic = rs.content.thumbPath;
                                        if (rs.senderUserId==that.user_info.user_id) {
                                            var data = {
                                                talk_type: "talk",
                                                type: '0',
                                                name: that.user_info.username,
                                                head_img: that.user_info.head_img,
                                                content: '',
                                                is_img: 1,
                                                img:bpic
                                            }
                                        } else {
                                            var data = {
                                                talk_type: "talk",
                                                type: '1',
                                                name: api.pageParam.uname,
                                                head_img: api.pageParam.uimg,
                                                content: '',
                                                is_img: 1,
                                                img:bpic
                                            }
                                        }
                                        content.push(data)
                                        that.content = content
                                    }
                                }
                                pageDown(300);
                            }
                        }
                    })
                }
                api.setCustomRefreshHeaderInfo({
                    bgColor : '#ffffff',
                    // image : {
                    //         pull : ['widget://image/1.png', 'widget://image/2.png', 'widget://image/3.png', 'widget://image/4.png', 'widget://image/5.png', 'widget://image/6.png', 'widget://image/7.png', 'widget://image/8.png'],
                    //         load : ['widget://image/8.png', 'widget://image/7.png', 'widget://image/6.png', 'widget://image/5.png', 'widget://image/4.png', 'widget://image/3.png', 'widget://image/2.png', 'widget://image/1.png']
                    // }
                }, function() {
                    getHistoryMessages(api.pageParam.uid, 'PRIVATE');
                    setTimeout(function() {
                            api.refreshHeaderLoadDone();
                    }, 3000)
                });
                //下拉加载历史记录
                function getHistoryMessages(targetId, conversationType) {
                    var rong = api.require('rongCloud2');
                    var oldid = that.oldid
                    rong.getHistoryMessages({
                        conversationType : conversationType,
                        targetId : targetId,
                        oldestMessageId : oldid,
                        count : 8
                    }, function(ret, err) {
                        // console.log(JSON.stringify(ret))
                        if (ret.status == 'success') {
                            var content = that.content
                            if (ret.result && ret.result.length > 0) {
                                // console.log(ret.result[ret.result.length - 1].messageId)
                                that.oldid= ret.result[ret.result.length - 1].messageId
                                for (var i = ret.result.length - 1; i >= 0; i--) {
                                    var rs = ret.result[i];
                                    if (rs.objectName == 'RC:TxtMsg') {
                                        jsxx = rs.content.text.replace(reg, function(a, b) {
                                            return face[a] ? face[a] : a;
                                        });
                                        if (rs.messageDirection == 'SEND') {
                                            var data = {
                                                talk_type: "talk",
                                                type: '0',
                                                name: that.user_info.username,
                                                head_img: that.user_info.head_img,
                                                content: jsxx,
                                                is_img: 0,
                                            }
                                        } else {
                                            var data = {
                                                talk_type: "talk",
                                                type: '1',
                                                name: api.pageParam.uname,
                                                head_img: api.pageParam.uimg,
                                                content: jsxx,
                                                is_img: 0,
                                            }
                                        }
                                        content.unshift(data)
                                        that.content = content
                                    } else if (rs.objectName == 'RC:ImgMsg') {
                                        var bpic = rs.content.imageUrl;
                                        var spic = rs.content.thumbPath;
                                        if (rs.messageDirection == 'SEND') {
                                            var data = {
                                                talk_type: "talk",
                                                type: '0',
                                                name: that.user_info.username,
                                                head_img: that.user_info.head_img,
                                                content: jsxx,
                                                is_img: 1,
                                                img:bpic
                                            }
                                        } else {
                                            var data = {
                                                talk_type: "talk",
                                                type: '1',
                                                name: api.pageParam.uname,
                                                head_img: api.pageParam.uimg,
                                                content: jsxx,
                                                is_img: 1,
                                                img:bpic
                                            }
                                        }
                                        content.unshift(data)
                                        that.content = content
                                    }
                                }
                                pageDown(300);
                                api.refreshHeaderLoadDone();
                            } else {
                                    api.toast({
                                            msg : '木有了消息啦…'
                                    });
                                    api.refreshHeaderLoadDone();
                            }
                        }
                    })
                }

                getLatestMessages(api.pageParam.uid,'PRIVATE')
                UIChatTools.open({
                    chatBox: {
                        placeholder: '聊天内容',
                        autoFocus: false,
                        maxRows: 6
                    },
                    styles: {
                        bgColor: '#f4f4f4',
                        margin: 10,
                    },
                    tools: {
                        h: 44,
                        iconSize: 30,
                        image: {
                            normal: 'fs://UIChatTolls/image.png',
                            selected: 'fs://UIChatTolls/image1.png'
                        },
                        face: {
                            normal: 'fs://UIChatTolls/face.png',
                            selected: 'fs://UIChatTolls/face1.png'
                        },
                    },
                    emotions: ['widget://res/emotions/basic']
                }, function(ret) {
                    if (ret) {
                        // api.alert({
                        //     msg: JSON.stringify(ret)
                        // });
                        if (ret.eventType == "send") {
                            if (!ret.msg) {
                                api.toast({
                                    msg: '不能发送空白消息',
                                    duration: 1000,
                                    location: 'center'
                                });
                                return false
                            }
                            if (!$api.trimAll(ret.msg)) {
                                api.toast({
                                    msg: '不能发送空白消息',
                                    duration: 1000,
                                    location: 'center'
                                });
                            } else {
                                var extra = {
                                    user_id:that.user_info.user_id,
                                    head_img:that.user_info.head_img,
                                    username:that.user_info.username,
                                }
                                rong.sendTextMessage({
                                    conversationType: 'PRIVATE',
                                    targetId: api.pageParam.uid,
                                    text: ret.msg,
                                    extra: JSON.stringify(extra)
                                }, function(ret, err) {
                                    // console.log(JSON.stringify(ret))
                                    // console.log(JSON.stringify(err))
                                    if (ret.status == 'prepare') {
                                        xx = ret.result.message.content.text.replace(reg, function(a, b) {
                                            return face[a] ? face[a] : a;
                                        });
                                    } else if (ret.status == 'success') {
                                        console.log(xx)
                                        var content = that.content
                                        var data = {
                                            talk_type: "talk",
                                            type: '0',
                                            name: that.user_info.username,
                                            head_img: that.user_info.head_img,
                                            content: xx,
                                            is_img: 0,
                                        }
                                        content.push(data)
                                        that.content = content

                                    }
                                });
                            }
                            pageDown(300);
                            UIChatTools.clearText();
                        }
                    }
                });
                //相册选图
                UIChatTools.imageListener(function(ret) {
                    if (ret.eventType == 'send') {
                        // console.log(JSON.stringify(ret))
                        for (var a = 0; a < ret.images.length; a++) {
                            // console.log(JSON.stringify(ret.images[a]))
                            var img = ret.images[a]; //图片路径
                            var content = that.content
                            // console.log(img)
                            var data = {
                                talk_type: "talk",
                                type: '0',
                                name: that.user_info.username,
                                head_img: that.user_info.head_img,
                                content: "",
                                is_img: 1,
                                img: img,
                            };
                            content.push(data)
                            // console.log(JSON.stringify(content))

                            var extra = {
                                user_id:that.user_info.user_id,
                                head_img:that.user_info.head_img,
                                username:that.user_info.username,
                            }
                            rong.sendImageMessage({
                                conversationType: 'PRIVATE',
                                targetId: api.pageParam.uid,
                                imagePath: img,
                                extra: JSON.stringify(extra),
                            }, function(ret, err) {
                                // console.log(JSON.stringify(ret))
                                // console.log(JSON.stringify(err))
                                if (ret.status == 'prepare') {
                                    that.content = content
                                }
                            });
                        }
                        UIChatTools.closeBoard();
                    } else {
                        api.toast({
                            msg: '图像获取失败',
                            duration: 3000,
                            location: 'bottom'
                        });
                        UIChatTools.closeBoard();
                    }
                });
                //表情符号转换
                var reg = /\[.+?\]/g;
                var face = {
                    '[微笑]': '<span><img src="../../../../res/emotions/basic/Expression_1.png"  width="28"/></span>',
                    '[撇嘴]': '<span><img src="../../../../res/emotions/basic/Expression_2.png"  width="28" /></span>',
                    '[色]': '<span><img src="../../../../res/emotions/basic/Expression_3.png"  width="28" /></span>',
                    '[发呆]': '<span><img src="../../../../res/emotions/basic/Expression_4.png"  width="28" /></span>',
                    '[得意]': '<span><img src="../../../../res/emotions/basic/Expression_5.png"  width="28" /></span>',
                    '[流泪]': '<span><img src="../../../../res/emotions/basic/Expression_6.png"  width="28" /></span>',
                    '[害羞]': '<span><img src="../../../../res/emotions/basic/Expression_7.png"  width="28" /></span>',
                    '[闭嘴]': '<span><img src="../../../../res/emotions/basic/Expression_8.png"  width="28" /></span>',
                    '[睡]': '<span><img src="../../../../res/emotions/basic/Expression_9.png"  width="28" /></span>',
                    '[大哭]': '<span><img src="../../../../res/emotions/basic/Expression_10.png"  width="28"/></span>',
                    '[尴尬]': '<span><img src="../../../../res/emotions/basic/Expression_11.png"  width="28"/></span>',
                    '[发怒]': '<span><img src="../../../../res/emotions/basic/Expression_12.png"  width="28"/></span>',
                    '[调皮]': '<span><img src="../../../../res/emotions/basic/Expression_13.png"  width="28" /></span>',
                    '[呲牙]': '<span><img src="../../../../res/emotions/basic/Expression_14.png"  width="28" /></span>',
                    '[惊讶]': '<span><img src="../../../../res/emotions/basic/Expression_15.png"  width="28" /></span>',
                    '[难过]': '<span><img src="../../../../res/emotions/basic/Expression_16.png"  width="28" /></span>',
                    '[酷]': '<span><img src="../../../../res/emotions/basic/Expression_17.png"  width="28" /></span>',
                    '[冷汗]': '<span><img src="../../../../res/emotions/basic/Expression_18.png"  width="28" /></span>',
                    '[抓狂]': '<span><img src="../../../../res/emotions/basic/Expression_19.png"  width="28" /></span>',
                    '[吐]': '<span><img src="../../../../res/emotions/basic/Expression_20.png"  width="28" /></span>',
                    '[偷笑]': '<span><img src="../../../../res/emotions/basic/Expression_21.png"  width="28" /></span>',
                    '[愉快]': '<span><img src="../../../../res/emotions/basic/Expression_22.png"  width="28" /></span>',
                    '[白眼]': '<span><img src="../../../../res/emotions/basic/Expression_23.png"  width="28" /></span>',
                    '[傲慢]': '<span><img src="../../../../res/emotions/basic/Expression_24.png"  width="28" /></span>',
                    '[饥饿]': '<span><img src="../../../../res/emotions/basic/Expression_25.png"  width="28" /></span>',
                    '[困]': '<span><img src="../../../../res/emotions/basic/Expression_26.png"  width="28" /></span>',
                    '[恐惧]': '<span><img src="../../../../res/emotions/basic/Expression_27.png"  width="28" /></span>',
                    '[流汗]': '<span><img src="../../../../res/emotions/basic/Expression_28.png"  width="28" /></span>',
                    '[憨笑]': '<span><img src="../../../../res/emotions/basic/Expression_29.png"  width="28" /></span>',
                    /*从这*/
                    '[悠闲]': '<span><img src="../../../../res/emotions/basic/Expression_30.png"  width="28" /></span>',
                    '[奋斗]': '<span><img src="../../../../res/emotions/basic/Expression_31.png"  width="28" /></span>',
                    '[咒骂]': '<span><img src="../../../../res/emotions/basic/Expression_32.png"  width="28" /></span>',
                    '[疑问]': '<span><img src="../../../../res/emotions/basic/Expression_33.png"  width="28" /></span>',
                    '[嘘]': '<span><img src="../../../../res/emotions/basic/Expression_34.png"  width="28" /></span>',
                    '[晕]': '<span><img src="../../../../res/emotions/basic/Expression_35.png"  width="28" /></span>',
                    '[疯了]': '<span><img src="../../../../res/emotions/basic/Expression_36.png"  width="28" /></span>',
                    '[衰]': '<span><img src="../../../../res/emotions/basic/Expression_37.png"  width="28" /></span>',
                    '[骷髅]': '<span><img src="../../../../res/emotions/basic/Expression_38.png"  width="28" /></span>',
                    '[敲打]': '<span><img src="../../../../res/emotions/basic/Expression_39.png"  width="28"/></span>',
                    '[再见]': '<span><img src="../../../../res/emotions/basic/Expression_40.png"  width="28"/></span>',
                    '[擦汗]': '<span><img src="../../../../res/emotions/basic/Expression_41.png"  width="28"/></span>',
                    '[抠鼻]': '<span><img src="../../../../res/emotions/basic/Expression_42.png"  width="28" /></span>',
                    '[鼓掌]': '<span><img src="../../../../res/emotions/basic/Expression_43.png"  width="28" /></span>',
                    '[糗大了]': '<span><img src="../../../../res/emotions/basic/Expression_44.png"  width="28" /></span>',
                    '[坏笑]': '<span><img src="../../../../res/emotions/basic/Expression_45.png"  width="28" /></span>',
                    '[左哼哼]': '<span><img src="../../../../res/emotions/basic/Expression_46.png"  width="28" /></span>',
                    '[右哼哼]': '<span><img src="../../../../res/emotions/basic/Expression_47.png"  width="28" /></span>',
                    '[哈欠]': '<span><img src="../../../../res/emotions/basic/Expression_48.png"  width="28" /></span>',
                    '[鄙视]': '<span><img src="../../../../res/emotions/basic/Expression_49.png"  width="28" /></span>',
                    '[委屈]': '<span><img src="../../../../res/emotions/basic/Expression_50.png"  width="28" /></span>',
                    '[快哭了]': '<span><img src="../../../../res/emotions/basic/Expression_51.png"  width="28" /></span>',
                    '[阴险]': '<span><img src="../../../../res/emotions/basic/Expression_52.png"  width="28" /></span>',
                    '[亲亲]': '<span><img src="../../../../res/emotions/basic/Expression_53.png"  width="28" /></span>',
                    '[吓]': '<span><img src="../../../../res/emotions/basic/Expression_54.png"  width="28" /></span>',
                    '[可怜]': '<span><img src="../../../../res/emotions/basic/Expression_55.png"  width="28" /></span>',
                    '[菜刀]': '<span><img src="../../../../res/emotions/basic/Expression_56.png"  width="28" /></span>',
                    '[西瓜]': '<span><img src="../../../../res/emotions/basic/Expression_57.png"  width="28" /></span>',
                    '[啤酒]': '<span><img src="../../../../res/emotions/basic/Expression_58.png"  width="28" /></span>',
                    '[篮球]': '<span><img src="../../../../res/emotions/basic/Expression_59.png"  width="28" /></span>',
                    '[乒乓]': '<span><img src="../../../../res/emotions/basic/Expression_60.png"  width="28" /></span>',
                    '[咖啡]': '<span><img src="../../../../res/emotions/basic/Expression_61.png"  width="28" /></span>',
                    '[饭]': '<span><img src="../../../../res/emotions/basic/Expression_62.png"  width="28" /></span>',
                    '[猪头]': '<span><img src="../../../../res/emotions/basic/Expression_63.png"  width="28" /></span>',
                    '[玫瑰]': '<span><img src="../../../../res/emotions/basic/Expression_64.png"  width="28" /></span>',
                    '[凋谢]': '<span><img src="../../../../res/emotions/basic/Expression_65.png"  width="28" /></span>',
                    '[嘴唇]': '<span><img src="../../../../res/emotions/basic/Expression_66.png"  width="28" /></span>',
                    '[爱心]': '<span><img src="../../../../res/emotions/basic/Expression_67.png"  width="28" /></span>',
                    '[心碎]': '<span><img src="../../../../res/emotions/basic/Expression_68.png"  width="28"/></span>',
                    '[蛋糕]': '<span><img src="../../../../res/emotions/basic/Expression_69.png"  width="28"/></span>',
                    '[闪电]': '<span><img src="../../../../res/emotions/basic/Expression_70.png"  width="28"/></span>',
                    '[炸弹]': '<span><img src="../../../../res/emotions/basic/Expression_71.png"  width="28" /></span>',
                    '[刀]': '<span><img src="../../../../res/emotions/basic/Expression_72.png"  width="28" /></span>',
                    '[足球]': '<span><img src="../../../../res/emotions/basic/Expression_73.png"  width="28" /></span>',
                    '[瓢虫]': '<span><img src="../../../../res/emotions/basic/Expression_74.png"  width="28" /></span>',
                    '[便便]': '<span><img src="../../../../res/emotions/basic/Expression_75.png"  width="28" /></span>',
                    '[月亮]': '<span><img src="../../../../res/emotions/basic/Expression_76.png"  width="28" /></span>',
                    '[太阳]': '<span><img src="../../../../res/emotions/basic/Expression_77.png"  width="28" /></span>',
                    '[礼物]': '<span><img src="../../../../res/emotions/basic/Expression_78.png"  width="28" /></span>',
                    '[拥抱]': '<span><img src="../../../../res/emotions/basic/Expression_79.png"  width="28" /></span>',
                    '[强]': '<span><img src="../../../../res/emotions/basic/Expression_80.png"  width="28" /></span>',
                    '[弱]': '<span><img src="../../../../res/emotions/basic/Expression_81.png"  width="28" /></span>',
                    '[握手]': '<span><img src="../../../../res/emotions/basic/Expression_82.png"  width="28" /></span>',
                    '[胜利]': '<span><img src="../../../../res/emotions/basic/Expression_83.png"  width="28" /></span>',
                    '[抱拳]': '<span><img src="../../../../res/emotions/basic/Expression_84.png"  width="28" /></span>',
                    '[勾引]': '<span><img src="../../../../res/emotions/basic/Expression_85.png"  width="28" /></span>',
                    '[拳头]': '<span><img src="../../../../res/emotions/basic/Expression_86.png"  width="28" /></span>',
                    '[差劲]': '<span><img src="../../../../res/emotions/basic/Expression_87.png"  width="28" /></span>',
                    '[爱你]': '<span><img src="../../../../res/emotions/basic/Expression_88.png"  width="28" /></span>',
                    '[NO]': '<span><img src="../../../../res/emotions/basic/Expression_89.png"  width="28" /></span>',
                    '[OK]': '<span><img src="../../../../res/emotions/basic/Expression_90.png"  width="28" /></span>',
                    '[爱情]': '<span><img src="../../../../res/emotions/basic/Expression_91.png"  width="28" /></span>',
                    '[飞吻]': '<span><img src="../../../../res/emotions/basic/Expression_92.png"  width="28" /></span>',
                    '[跳跳]': '<span><img src="../../../../res/emotions/basic/Expression_93.png"  width="28" /></span>',
                    '[发抖]': '<span><img src="../../../../res/emotions/basic/Expression_94.png"  width="28" /></span>',
                    '[怄火]': '<span><img src="../../../../res/emotions/basic/Expression_95.png"  width="28" /></span>',
                    '[转圈]': '<span><img src="../../../../res/emotions/basic/Expression_96.png"  width="28" /></span>',
                    '[磕头]': '<span><img src="../../../../res/emotions/basic/Expression_97.png"  width="28"/></span>',
                    '[回头]': '<span><img src="../../../../res/emotions/basic/Expression_98.png"  width="28"/></span>',
                    '[跳绳]': '<span><img src="../../../../res/emotions/basic/Expression_99.png"  width="28"/></span>',
                    '[投降]': '<span><img src="../../../../res/emotions/basic/Expression_100.png"  width="28" /></span>',
                    '[激动]': '<span><img src="../../../../res/emotions/basic/Expression_101.png"  width="28" /></span>',
                    '[街舞]': '<span><img src="../../../../res/emotions/basic/Expression_102.png"  width="28" /></span>',
                    '[献吻]': '<span><img src="../../../../res/emotions/basic/Expression_103.png"  width="28" /></span>',
                    '[左太极]': '<span><img src="../../../../res/emotions/basic/Expression_104.png"  width="28" /></span>',
                    '[右太极]': '<span><img src="../../../../res/emotions/basic/Expression_105.png"  width="28" /></span>'
                };
                //消息监听
                function jtxx(that) {
                    var rong = api.require('rongCloud2');
                    console.log("111111")

                    rong.setOnReceiveMessageListener(function(ret, err) {
                        console.log(JSON.stringify(ret));
                        if (ret) {
                            if (ret.result.message.targetId == api.pageParam.uid) {
                                if (ret.result.message.objectName == 'RC:TxtMsg') {
                                    txt = ret.result.message.content.text.replace(reg, function(a, b) {
                                        return face[a] ? face[a] : a;
                                    });
                                    var content = that.content
                                    var data = {
                                        talk_type: "talk",
                                        type: '1',
                                        name: api.pageParam.uname,
                                        head_img: api.pageParam.uimg,
                                        content: txt,
                                        is_img: 0,
                                        img: ""
                                    }
                                    content.push(data)
                                    that.content = content
                                }
                                if (ret.result.message.objectName == 'RC:ImgMsg') {
                                    var content = that.content
                                    var img = ret.result.message.content.imageUrl
                                    var data = {
                                        talk_type: "talk",
                                        type: '1',
                                        name: api.pageParam.uname,
                                        head_img: api.pageParam.uimg,
                                        content: "",
                                        is_img: 1,
                                        img: img
                                    }
                                    content.push(data)
                                    that.content = content
                                }
                                setTimeout(function() {
                                    window.scrollTo(0, document.body.scrollHeight);
                                }, 300)
                            }
                        }
                    })
                }
            },
            methods: {

            }
        })



    };



    function goBack() {
        api.closeWin({

        });
    }
    //时间差计算
    function sj(sj) {
        var nowt = new Date().getTime();
        var a = new Date(parseInt(sj));
        var b = new Date(parseInt(nowt));
        var date1 = Date.parse(format(a, 4));
        var date2 = Date.parse(format(b, 4));
        var xxsj = Math.ceil((date2 - date1) / (60 * 1000))
        if (xxsj <= 1 && xxsj >= 0) {
            return "就刚才";
        } else if (xxsj <= 10 && xxsj > 1) {
            return xxsj + "分钟前";
        } else if (xxsj <= 60 && xxsj > 10) {
            return format(a, 1);
        } else if (xxsj <= 1440 && xxsj > 60) {
            return format(a, 1);
        } else if (xxsj <= 10080 && xxsj > 1440) {
            return format(a, 2);
        } else if (xxsj > 10080) {
            return format(a, 3);
        } else {
            return format(a, 3);
        }
    }

    //格式化时间
    function format(now, type) {
        var show_day = new Array('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六');
        var year = now.getFullYear().toString();
        var month = (now.getMonth() + 1).toString();
        var day = (now.getDate()).toString();
        var tian = now.getDay().toString();
        var hour = (now.getHours()).toString();
        var minute = (now.getMinutes()).toString();
        var second = (now.getSeconds()).toString();
        if (hour.length == 1) {
            hour = "0" + hour;
        }
        if (minute.length == 1) {
            minute = "0" + minute;
        }
        if (second.length == 1) {
            second = "0" + second;
        }
        if (type == 1) {
            var dateTime = hour + ":" + minute;
        } else if (type == 2) {
            var dateTime = show_day[tian] + " " + hour + ":" + minute
        } else if (type == 3) {
            var dateTime = year + "-" + month + "-" + day
        } else if (type == 4) {
            var dateTime = year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second;
        } else if (type == 5) {
            var dateTime = show_day[tian];
        }
        return dateTime;
    }
    function pageDown(time) {
        setTimeout(function() {
            api.pageDown({
                    bottom : true,
                    animate : true
                }, function(ret) {
            });
        }, time || 0)
    }
</script>

</html>
